import { MULTIPLE_NUM } from '@/configs/game.config';
import {
  HOST_RONG_POINT_CONFIG,
  GUEST_RONG_POINT_CONFIG,
  HOST_ZIMO_POINT_CONFIG,
  GUEST_ZIMO_POINT_CONFIG,
} from '@/configs/points.config';

/** 获取点炮所得点数
 * @param multiple 翻数
 * @param signNum 符数
 * @param isHost 胡牌人是否为亲家
 */
export function getTriggerPointNum(
  multiple: MULTIPLE_NUM,
  signNum: number,
  isHuHost: boolean,
  courtNum = 0,
) {
  let pointNum: number;
  if (isHuHost) {
    if (multiple === MULTIPLE_NUM.YAKUMAN) {
      pointNum = 48000;
    } else if (multiple === MULTIPLE_NUM.TRIPLE_SLAM) {
      pointNum = 36000;
    } else if (multiple === MULTIPLE_NUM.DOUBLE_SLAM) {
      pointNum = 24000;
    } else if (multiple === MULTIPLE_NUM.OVER_SLAM) {
      pointNum = 18000;
    } else if (
      multiple === MULTIPLE_NUM.SLAM ||
      (multiple === MULTIPLE_NUM.MULTIPLE_FOUR && signNum >= 40)
    ) {
      pointNum = 12000;
    } else {
      pointNum = (HOST_RONG_POINT_CONFIG[multiple][signNum] as number) || 1000;
    }
  } else {
    if (multiple >= MULTIPLE_NUM.YAKUMAN) {
      pointNum = 36000;
    } else if (multiple >= MULTIPLE_NUM.TRIPLE_SLAM) {
      pointNum = 24000;
    } else if (multiple >= MULTIPLE_NUM.DOUBLE_SLAM) {
      pointNum = 18000;
    } else if (multiple >= MULTIPLE_NUM.OVER_SLAM) {
      pointNum = 12000;
    } else if (
      multiple >= MULTIPLE_NUM.SLAM ||
      (multiple === MULTIPLE_NUM.MULTIPLE_FOUR && signNum >= 40)
    ) {
      pointNum = 8000;
    } else {
      pointNum = (GUEST_RONG_POINT_CONFIG[multiple][signNum] as number) || 1000;
    }
  }
  return pointNum + 300 * courtNum;
}

/**
 * 获取亲家自摸胡牌时每个子家应付的点数
 * @param multiple 翻数
 * @param signNum 符数
 */
export function getHostAveragePointNum(
  multiple: MULTIPLE_NUM,
  signNum: number,
  courtNum = 0,
) {
  let pointNum: number = 500;
  if (multiple >= MULTIPLE_NUM.YAKUMAN) {
    pointNum = 16000;
  } else if (multiple >= MULTIPLE_NUM.TRIPLE_SLAM) {
    pointNum = 12000;
  } else if (multiple >= MULTIPLE_NUM.DOUBLE_SLAM) {
    pointNum = 8000;
  } else if (multiple >= MULTIPLE_NUM.OVER_SLAM) {
    pointNum = 6000;
  } else if (
    multiple >= MULTIPLE_NUM.SLAM ||
    (multiple >= MULTIPLE_NUM.MULTIPLE_FOUR && signNum >= 40)
  ) {
    pointNum = 4000;
  } else {
    pointNum = (HOST_ZIMO_POINT_CONFIG[multiple][signNum] as number) || 1000;
  }
  return pointNum + 100 * courtNum;
}

/**
 * 获取子家自摸胡牌时亲家和子家各付的点数
 */
export function getGuestAveragePointNums(
  multiple: MULTIPLE_NUM,
  signNum: number,
  courtNum = 0,
) {
  let hostPointNum: number = 500;
  let guestPointNum: number = 300;
  if (multiple >= MULTIPLE_NUM.YAKUMAN) {
    [hostPointNum, guestPointNum] = [16000, 8000];
  } else if (multiple >= MULTIPLE_NUM.TRIPLE_SLAM) {
    [hostPointNum, guestPointNum] = [12000, 6000];
  } else if (multiple >= MULTIPLE_NUM.DOUBLE_SLAM) {
    [hostPointNum, guestPointNum] = [8000, 4000];
  } else if (multiple >= MULTIPLE_NUM.OVER_SLAM) {
    [hostPointNum, guestPointNum] = [6000, 3000];
  } else if (
    multiple >= MULTIPLE_NUM.SLAM ||
    (multiple >= MULTIPLE_NUM.MULTIPLE_FOUR && signNum >= 40)
  ) {
    [hostPointNum, guestPointNum] = [4000, 2000];
  } else {
    [hostPointNum, guestPointNum] = (GUEST_ZIMO_POINT_CONFIG[multiple][
      signNum
    ] as [number, number]) || [500, 300];
  }
  return [hostPointNum + 100 * courtNum, guestPointNum + 100 * courtNum];
}
